package com.warm.redis;


import com.warm.core.utils.JsonUtil;
import org.noear.solon.data.cache.Serializer;

/**
 * @author noear
 * @since 1.5
 */
public class JsonSerializer implements Serializer<String> {
    public static final JsonSerializer instance = new JsonSerializer();

    @Override
    public String name() {
        return "Json";
    }

    @Override
    public String serialize(Object obj) {
        if (obj == null) {
            return null;
        }

        return JsonUtil.objectToJson(obj);
    }

    @Override
    public Object deserialize(String data) {
        if (data == null) {
            return null;
        }

        return JsonUtil.jsonToObject(data, Object.class);
    }
}
